<template>
	<view class="box">
		<u-navbar title="管理员列表" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#666" titleStyle="color:#333" bgColor="#E0DDDA" :rightText="righttxt" @rightClick="right"
				@leftClick="leftClick"></u-navbar>
		<view class="main">
			<checkbox-group @change="checkboxChangeAll">
				<view class="item" v-for="item in merberlist" :key="item.id">
					<image :src="item.member.head_img" mode="aspectFill"></image>
					<text>{{item.member.nickname}}</text>
					<view class="tag" v-if="item.is_admin==1">
						群主
					</view>
					<view class="tag" v-if="item.is_admin==2">
						管理员
					</view>
					<checkbox v-if="isshow" borderColor="#fff" activeBorderColor="#A68A64"
						activeBackgroundColor="#A68A64" backgroundColor="#f2f2f2" :checked="false"
						:value="item.member_id.toString()"></checkbox>
				</view>
				</checkbox-group>
		</view>
		<noDatas  :xxxList="merberlist" :showMore="false"></noDatas>
		<view style="width: 750rpx;height: 88rpx;">
			
		</view>
	</view>
</template>

<script>
	import {groupDetails,adminList,setAdministrator} from "../../api/hx.js"
	import {getuserinfo}from "../../api/index.js"
	export default{
		data(){
			return{
				selectedIds:[],
				isshow:false,
				righttxt:"管理成员",
				word:"",
				merberlist:[],
				groupid:"",
				tit:"",
				groupinfo:"",
				is_admin:"",
				user:{},
				
			}
		},
		onLoad(option) {
			this.groupid=option.id
			this.getlist()
			this.groupdetail()
		},
		onShow() {
			this.groupdetail()
			this.getuser()
		},
		methods:{
			set(){
				setAdministrator({
					hx_group_id:this.groupid,
					is_admin:"0",
					admin_member_id:this.selectedIds.join(",")
				}).then(res=>{
					if(res.code==1){
						this.getlist()
						this.selectedIds=[]
						this.righttxt="管理成员"
						this.isshow=false
					}
					uni.$u.toast(res.msg)
					// console.log()
				})
			},
			getuser(){
				getuserinfo().then(res=>{
					this.user=res.data
				})
			},
			gomore(item){
				if(this.is_admin!=0&&this.user.id!=item.member_id){
			
				uni.setStorageSync("groupitem",item)
				uni.navigateTo({
					url:"/pagesMy/chat/more?id="+this.groupid
				})
					
				}
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			sub(){
				this.page=1,
				this.getlist()
			},
			groupdetail() {
				groupDetails({
					hx_group_id: this.groupid
				}).then(res => {
					if (res.code == 1) {
						this.groupinfo = res.data
						this.is_admin=res.data.group_member_one.is_admin
						this.tit = `${this.groupinfo.name}(${this.groupinfo.member_number}人)`
						// console.log("群详情", res)
					} else {
						uni.$u.toast(res.msg)
					}
			
				})
			},
			getlist(){
				adminList({
					hx_group_id:this.groupid,

				}).then(res=>{
					if (res.code == 1) {
						this.merberlist = res.data
				
					}
				})
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			right(){
				this.isshow=true
				this.righttxt="删除管理员"
				if(this.selectedIds.length!=0){
					this.set()
					
					this.righttxt="管理成员"
					
				}
			},
			checkboxChangeAll(e) {
				this.selectedIds = e.detail.value;
				console.log(this.selectedIds)
			},
		},

	}
</script>
<style>
	page{
		background-color:#E0DDDA;
	}
</style>
<style lang="scss">
	.box{
		width: 750rpx;
		
	}
	/deep/ .u-navbar__content__right__text {
		color: #FF1616;
	}
	.wrap_top{
		width: 750rpx;
	}
	.search{
		width: 690rpx;
		height: 72rpx;
		background: #E0DDDA;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 0 auto;
		position: relative;
		>image{
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;
			
		}
		>input{
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: rgba(255,255,255,0.8);
		}
	}
	.main{
		width: 750rpx;
		
	}
	.item{
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;
		>image{
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}
		>text{
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 15rpx;
			max-width: 300rpx;
			white-space: nowrap; /* 防止文本换行 */
			  overflow: hidden;   /* 隐藏溢出的文本 */
			  text-overflow: ellipsis; /* 当文本溢出时显示省略号 */
		}
		.tag{
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: #A68A64;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: #fff;
			text-align: center;
			margin-left: 20rpx;
		}
		/deep/.uni-checkbox-input {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 40rpx;
			border-radius: 50%;
		}
		
	}
	
</style>